<?php
	// Using session-variables to keep track of logged in users
	session_start();
	
	// Includes
	require_once "MasterView.php";
	require_once "MasterHandler.php";
	
	require_once "Common/Page.php";
	
	require_once "Database/DBConfig.php";
	require_once "Database/Database.php";
	
	require_once "Login/LoginController.php";
	require_once "FileUpload/FileUploadController.php";
	require_once "Registration/RegistrationController.php";
	
	class MasterController
	{
		public static function DoControl()
		{
			// MasterView and MasterHandler
			$masterView = new MasterView();
			$masterHandler = new MasterHandler();
			
			// The databse used for the module
			$db = new Database();
			$db->Connect(new DBConfig("community_db"));
			
			// Different controllers
			$loginController = new LoginController();
			$fileUploadController = new FileUploadController();
			$registrationController = new RegistrationController();
			
			// Set the active view
			$masterView->SetView();
			
			// Generate the content of the site
			$content = "";
			$navigationBar = NULL;
			
			if ($masterView->IsViewingHome())
			{
				$content .= $loginController->DoControl($db);
				$content .= $fileUploadController->DoControl($db);
			}
			else if ($masterView->IsViewingRegistration())
				$content .= $registrationController->DoControl($db);
			else
			{
				$content .= $loginController->DoControl($db);
				$content .= $fileUploadController->DoControl($db);
			}
			
			$db->Close();
			
			// Generate a return a HTML5 page
			$page = new \Common\Page();
			$page->AddStylesheet("Style/Style.css");
			$page->AddJavascript("Behaviour/Behaviour.js");
			
			return $page->GenerateHTML5Page("Module", $content, $masterView->DoLoggedOutNavigationBar());
		}
	}
	
	echo MasterController::DoControl();